/**
 * 调用Move 对像之前必须设置 dom_check_hand(allow_box_id,disallow_box_id)
 */
var Move = {
		/**
		 * 设置dom_check类
		 */
		 dom_check_hand : function (allow_box_id,disallow_box_id){
			return new dom_check(allow_box_id,disallow_box_id);
		},
		dom_post : function(url){
			return new ztree_post();
		}
		/*
		 * 检查是否可以移动树中元素
		 */
		dragTree2Dom : function (treeId,treeNodes){
			//拖拽之前,判断是组还是元素
			if(treeNodes[0].isParent == true){
				//drag department
				return true;
			}else if(treeNodes[0].isParent == false){
				//drag employee
				return true;
			}
			return false;
		}
		
		dropTree2Dom : function(e, treeId, treeNodes, targetNode, moveType) {
			window.console.log("dropTree2Dom");
			window.console.log(arguments);
			e.preventDefault();
			var target = e.target;
			if(Move.dom_check_hand.check_target(e.target) != false){
				//放对了地方
				
			}
		}
}

var dom_check = function (allow_box_id,disallow_box_id){
		this.allow_box_id = allow_box_id;	//public
		this.disallow_box_id = disallw_box_id; //public
		var droped_target_id; //private
		var drop_target_dom;
		
		this.check_target = function (target){
			if( !this.allow_box_id || !this.disallow_box_id){
				alert("id值没有正确的设置");
				return false;
			}//end of 检查值 是否存在
			
			if(typeof target == "object"){//dom 对像 用于ztree
				//dom object
				if (target.id == this.allow_box_id || (target.parentElement !=null && target.parentElement.id == this.allow_box_id )) {
					drop_target_dom = document.getElementById(this.allow_box_id);
					return true;
				} else if (target.id == this.disallow_box_id || (target.parentElement !=null && target.parentElement.id == this.disallow_box_id )) {
					drop_target_dom = document.getElementById(this.disallow_box_id);
					return true;
				} else {
					drop_target_dom = false;
					alert("没有放对地方");
					return false;
				}
				return false;

			}else if(typeof target == "string"){ //用于手动校验
//				$(target)
			}
		}
}

var ztree_post = {
	/**
	 * 权限id
	 */
	privilege_id : null,
	groupList : [],
	itemList : [],
	/**
	 * 设置列表中的组或元素
	 */
	set : function (id,name,is_allow,type){
		var obj = new Object();
		obj.id = id;
		obj.name = name;
		if (type == "group"){
			groupList.pust(obj);
			return true;
		}else if(type == "item"){
			itemList.push(obj);
			return true;
		}else{
			return false
		}
	},
	/**
	 * 通过id删除列表中的组或元素
	 */
	del : function (id,type){
		for (key in groupList){
			obj = groupList[key]
			if(obj.id == id){
				if(type == "group"){
					groupList.splice(key,1);
					return true;
				}else if(type == "item"){
					itemList.splice(key,1);
					return true;
				}else {
					return false;
				}
				break;
			}
		}
	},
	post : function (url,param){
		$.post(url,{
			});
	}
	
}
/**
 * 用于添加删除dom中按钮
 */
var dom_ztree = {
		/**
		 * target附加到的dom id
		 * id,name,is_allow,type属性
		 */
	add : function (id,name,is_allow,type,target){
		var new_dom = $("<span class='domBtn'></span>").text(name)
		new_dowm = new_dom.attr({id : "ztree_" + id, is_allow : is_allow , type : type});
		$("#"+target).append(new_dom).bind('click',dom_ztree.delthis);
	},
	delthis : function (e){
		dom_ztree.del(e.target.id);
		e.preventDefault();
	},
	del : function (id){
		$("#ztree_" + id).remove();
	}
}
